/**
 * @param {number} numRows
 * @return {number[][]}
 */
var generate = function(numRows) {
  let arr = [[1]];
  for(let i = 0; i < numRows - 1; i++) {
    let temp = [];
    for(let j = 0; j < arr[i].length + 1; j++) {
      if(j == 0) {
        temp[j] = arr[i][j];
      }
      else if(j == arr[i].length) {
        temp[j] = arr[i][arr[i].length - 1];
      } else {
        temp[j] = arr[i][j - 1] + arr[i][j];
      }
    }
    arr.push(temp);
  }

  return arr;
};
let numRows = 5;
console.log(generate(numRows));
numRows = 1;
console.log(generate(numRows));
numRows = 3;
console.log(generate(numRows));
